// import {baseUrl,apiPath} from './config'
import {apiPath, baseUrl, tenantId} from '@/utils/config';
import {getToken, removeToken} from './request/auth'

export const upload = (file:string, type:string="image") => {
    if (type === undefined || type === null) {
        type = "image"
    }
    return new Promise((resolve, reject) => {
        uni.uploadFile({
            url: baseUrl + apiPath + '/infra/file/upload',
            filePath: file,
            name: 'file',
            formData: {
                fileType: type
            },
            header: {
                // Accept: 'text/json',
                Accept: '*/*',
                'tenant-id': tenantId,
                // Authorization:  'Bearer test247',
            },
            success: (uploadFileRes) => {
                let result = JSON.parse(uploadFileRes.data);
                if (result.error === 1) {
                    uni.showToast({
                        icon: 'none',
                        title: result.msg,
                    });
                } else {
                    return resolve(result);
                }
            },
            fail: (error) => {
                console.log('上传失败：', error);
                return resolve(false);
            },
            complete: () => {
                // uni.hideLoading();
            },
        });
    });
}